New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
8266666: Implementation for snippets #4795
Conversation
This undoes use of the feature in JDK, but leaves the implementation.
👋 Welcome back prappo! A progress list of the required criteria for merging this PR into |
/contributor add jjg |
@pavelrappo |
/contributor add hannesw |
@pavelrappo |
@pavelrappo |
@pavelrappo The following labels will be automatically applied to this pull request:
When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing lists. If you would like to change these labels, use the /label pull request command. |
Webrevs
|
/csr |
@jonathan-gibbons this pull request will not be integrated until the CSR request JDK-8266669 for issue JDK-8266666 has been approved. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The overall structure looks generally good. Nice work.
That being said, I note the following ...
-
All new top-level classes should have a reasonable documention comment, including where appropriate the standard boilerplate (i.e. not on public API classes and interfaces)
* <p><b>This is NOT part of any supported API.
* If you write code that depends on this, you do so at your own risk.
* This code and its internal interfaces are subject to change or
* deletion without notice. -
All new non-private methods should have a reasonable documentation comment
-
There's more than a typical number of chatty comments and/or fixme comments and/or code that needs to be uncommented. I'll do a separate review pass to note some of those examples.
-
Please work with @hns to determine the proposed CSS style(s) to be used, and not just the interim placeholder
sandybrown
. The color should be compatible with the existing color palette. Ideally, at the same time, in either this changeset or a sibling changeset, we should change the style of a default<pre>{code}
block to be similar with respect to the basic display characteristics.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More feedback;
-
It seems reasonable to introduce the
...taglets.snippets
package. It seems excessive to have three sub packages within that, foractions
,parser
andtext
, especially when the last contains just a single class. -
At some point soonish, we will need API somewhere to get the content of the snippet. This is necessary to fulfill the goal in the JEP to support validation of snippet content. Without any such API, validation code would have to duplicate at least some of the code to handle snippets. This API should probably not be in
com.sun.source
and should probably be in thejdk.javadoc
module, perhaps on the existingStandardDoclet
class. One way to do that would be to introduce a utility interface to provide access to support for taglets, and then have a method onStandardDoclet
to access an instance of that utility for a specific snippet, identified by element and/or id.
src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlDocletWriter.java
Show resolved
Hide resolved
src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/resources/stylesheet.css
Outdated
Show resolved
Hide resolved
I'm ok with adding the boilerplate "This is NOT part of any supported API" note, as well as adding method comments where practical. However, I note that this PR comprises mostly an internal implementation and not a public API. Internal implementation comments are more like documentation rather than specification. Such documentation is virtually never built and is read in an IDE while eyeballing the respective code and tests. I think it's overkill and waste of resources to use doc comments in such a case.
I'm currently working on removing as many FIXMEs and TODOs as possible. I think of a FIXME comment as a "review breakpoint" that highlights an issue that has to be resolved before the code is accepted. I would be interested to learn which comments you consider "chatty". I look forward to fixing them with your help. One note, though. For an internal implementation, I try hard to make only the "why" comments, not the "what" comments. "What" comments have their place, but they should be sparing and reserved for non-trivial domains. For trivial domains, the "what" should be obvious. If it is not, I failed at coding, not at commenting. |
That package structure was initially there to keep the dependencies clear. That said, I'm okay with squashing it into a single package for practical reasons.
We can discuss that API either in this PR or in a separate thread on javadoc-dev at openjdk.java.net. (Separately: is this @/at trick still efficient? Modern email-address harvesting is surely smarter than that.) |
Mailing list message from Jonathan Gibbons on javadoc-dev: The comments don't need to be of core-libs quality, but at least some of Think of the comments as "pay it forward" to our future selves. -- Jon On 7/26/21 5:09 AM, Pavel Rappo wrote:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall the code looks good!
A few comments inline. I'll have a look at the stylesheet changes next.
src/jdk.compiler/share/classes/com/sun/source/doctree/SnippetTree.java
Outdated
Show resolved
Hide resolved
src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/taglets/SnippetTaglet.java
Outdated
Show resolved
Hide resolved
...c/share/classes/jdk/javadoc/internal/doclets/toolkit/taglets/snippet/text/AnnotatedText.java
Outdated
Show resolved
Hide resolved
src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/resources/stylesheet.css
Outdated
Show resolved
Hide resolved
...avadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/taglets/snippet/parser/Parser.java
Outdated
Show resolved
Hide resolved
Project conventions are more important than my preferences. Although I don't see much value in such comments, I added some in commit 4300903. |
This commit moves the contents of the jdk.javadoc.internal.doclets.toolkit.taglets.snippet.{action,parser,text} packages into the jdk.javadoc.internal.doclets.toolkit.taglets.snippet package.
DocCommentParser now recognizes end-of-input better. To test that in testBadTagSyntax, the ToolBox.writeJavaFiles approach was used instead that of ClassBuilder.write. This is because ClassBuilder muddled doc comments with extra formatting such as trailing newline. So from within `ClassBuilder.MethodBuilder.setComments(java.lang.String...)` one couldn't make an immediate end-of-input: there was always `\n` appended to the comment. Also reformatted testBadTagSyntax for ease of comparing input and expected error output.
Improves code style; reformats.
Removes stale FIXMEs, TODOs and comments; downgrades FIXMEs to TODOs where possible; wraps overly long lines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went through the changes again, they mostly look good. There are a few areas (mostly handling of tags and styled text) where I still want to do more exploring in order to better understand the code.
I left inline comments for minor issues/questions I encountered.
src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlDocletWriter.java
Show resolved
Hide resolved
src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/CommentUtils.java
Outdated
Show resolved
Hide resolved
src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/taglets/snippet/Parser.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The primary actionable item is that all strings that are intended for use in end-user error messages need to be localizable. i.e. see Parser.ParseException
Other comments are minor and can be deferred.
src/jdk.compiler/share/classes/com/sun/source/util/SimpleDocTreeVisitor.java
Show resolved
Hide resolved
src/jdk.compiler/share/classes/com/sun/tools/javac/parser/DocCommentParser.java
Outdated
Show resolved
Hide resolved
src/jdk.compiler/share/classes/com/sun/tools/javac/parser/DocCommentParser.java
Show resolved
Hide resolved
src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/TagletWriterImpl.java
Outdated
Show resolved
Hide resolved
src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/TagletWriterImpl.java
Outdated
Show resolved
Hide resolved
src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/taglets/snippet/Parser.java
Outdated
Show resolved
Hide resolved
src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/taglets/snippet/Parser.java
Outdated
Show resolved
Hide resolved
src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/taglets/snippet/Parser.java
Outdated
Show resolved
Hide resolved
src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/taglets/snippet/Parser.java
Outdated
Show resolved
Hide resolved
...vadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/taglets/snippet/ParseException.java
Outdated
Show resolved
Hide resolved
1. Reverts changes from CommentUtils.java (unused methods) 2. Changes misguided regex-related assertion to tests
* Cleans up error string format * Internationalizes error messages, mapping them to fewer resource keys * Fixes a few bugs related to error messages, including: inaccurate caret positioning and runaway resource name (i.e. the resource key wasn't translated into an error)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My primary concern in the last round of review was internationalization. You've addressed that: good.
When reading, and re-reading, a contribution this big, it's always possible to see new tiny details that could be improved. I've mentioned some here, and I'm sure that in times to come we will look at the code more and maybe see more tweaks. So, enough for now. Well done.
I note the varied references to improve JavadocTester.
# 0: path; 1: exception | ||
doclet.error_setting_snippet_path=\ | ||
Error setting snippet path {0}: {1} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add newline at end of file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although it wasn't there to begin with, adding it won't be as big a deal as reformatting code in other places you suggested earlier.
protected boolean isUnquotedAttrValueTerminator(char ch) { | ||
switch (ch) { | ||
case ':': // indicates that the instruction relates to the next line | ||
case ' ': case '\t': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about other whitespace? Is that already covered?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which other whitespace? If you are talking about \r
or \n
, then the string parsed by MarkupParser
cannot have those. MarkupParser
gets a single line without a trailing line terminator.
* | ||
* This exception is only used to capture a user-facing error message. | ||
* The message supplier is accepted not to control when to obtain a message, | ||
* but to abstract how to obtain in. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo "in"? maybe "one" or "it"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! It should've been "it".
|
||
/* | ||
* While the "id" and "lang" attributes are advertised in JEP 413, they are | ||
* currently unused by the implementation. The goal of this test is to make |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
id's should be propagated to the output HTML
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
About empty id's and propagating id's to the output HTML. I think we can address these in a follow-up issue. Would you be okay with it?
// This is because the below errors are modelled as exceptions thrown | ||
// at parse time, when there are no doc trees yet. And the above errors |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would read better as "the errors below" and "the errors above"
https://www.grammarphobia.com/blog/2012/12/below.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks.
} | ||
|
||
// TODO: perhaps this method could be added to JavadocTester | ||
private void checkOutputEither(Output out, String first, String... other) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- This method allows a call with just a single String arg.
- Given that the method allows many String args, the name might be better as
checkOneOf
Note to self/@jonathan-gibbons: review all references for suggestions to JavadocTester
@pavelrappo This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 4 new commits pushed to the
Please see this link for an up-to-date comparison between the source branch of this pull request and the ➡️ To integrate this PR with the above commit message to the |
Thanks for approving the change, Jon. Some of your suggestions are added to 884dcb0. |
/integrate |
Going to push as commit 0fc47e9.
Your commit was automatically rebased without conflicts. |
@pavelrappo Pushed as commit 0fc47e9. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
This PR implements JEP 413 "Code Snippets in Java API Documentation", which hasn't been yet proposed to target JDK 18. The PR starts as a squashed merge of the https://github.com/openjdk/jdk-sandbox/tree/jdk.javadoc/snippets branch.
Progress
Issue
Reviewers
Contributors
<jjg@openjdk.org>
<hannesw@openjdk.org>
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/4795/head:pull/4795
$ git checkout pull/4795
Update a local copy of the PR:
$ git checkout pull/4795
$ git pull https://git.openjdk.java.net/jdk pull/4795/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 4795
View PR using the GUI difftool:
$ git pr show -t 4795
Using diff file
Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/4795.diff